# Makefile for SSM3J93S Project

# Docker Compose files
DC_ARM=scripts/docker-compose.yaml
DC_AMD=scripts/docker-compose.linux-amd64.yaml

# Maven
MVN=./mvnw

# 自动检测平台
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)

ifeq ($(UNAME_S),Darwin)
	ifeq ($(UNAME_M),arm64)
		PLATFORM=arm
	else
		PLATFORM=amd
	endif
else
	ifeq ($(UNAME_M),x86_64)
		PLATFORM=amd
	else
		PLATFORM=arm
	endif
endif

# 自动适配平台的 compose 文件
ifeq ($(PLATFORM),arm)
	DC_AUTO=$(DC_ARM)
else
	DC_AUTO=$(DC_AMD)
endif

.PHONY: help up down build restart
help:
	@echo "用法: make [命令] (自动检测平台: $(PLATFORM))"
	@echo "  up         启动"
	@echo "  down       停止"
	@echo "  build      重建"
	@echo "  restart    重启"
	@echo "  logs       查看日志"
	@echo "  clean      Maven 清理"
	@echo "  install    Maven 安装依赖"
	@echo "  package    Maven 打包"
	@echo "  start      一键启动"

up:
	@echo "[INFO] 当前平台: $(PLATFORM)"
	docker compose -f $(DC_AUTO) up -d

down:
	@echo "[INFO] 当前平台: $(PLATFORM)"
	docker compose -f $(DC_AUTO) down

restart:
	make down && make up

build:
	@echo "[INFO] 当前平台: $(PLATFORM)"
	docker compose -f $(DC_AUTO) up -d --build

logs:
	@echo "[INFO] 当前平台: $(PLATFORM)"
	docker compose -f $(DC_AUTO) logs -f

clean:
	mvn clean

install:
	mvn install

package:
	mvn package

start:
	make clean && make install && make package && make down && make up
